#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int N = 10005;

struct node {
    int id;
    int x;
};


int n, m, b;
int f[N];
vector<node> a[N];
queue<int> Q;

bool spfa(int maxN)
{
    if (f[1] > maxN) return false;
    int w[N], is[N] = {};
    memset(w, 0x3f3f3f3f, sizeof w);
    w[1] = 0;
    Q.push(1);
    while (!Q.empty())
    {
        int u = Q.front(); Q.pop();
        is[u] = 0;
        for (int i = 0; i < a[u].size(); ++i)
        {
            int v = a[u][i].id, dis = w[u] + a[u][i].x;
            if (dis > b) continue;
            if (f[v] > maxN || dis >= w[v]) continue;
            if (v == n) return true;
            w[v] = dis;
            if (!is[v]) Q.push(v), is[v] = true;
        }
    }
    return false;
}

int main()
{
    cin >> n >> m >> b;
    for (int i = 1; i <= n; ++i)
    {
        cin >> f[i];
    }
    for (int i = 1; i <= m; ++i)
    {
        int v, u, c;
        cin >> u >> v >> c;
        a[u].push_back({ v,c });
        a[v].push_back({ u,c });
    }
    int left = 0, right = 1e9 + 10;
    while (left < right)
    {
        int mid = (left + right) >> 1;
        if (spfa(mid))
        {
            right = mid;
        }
        else left = mid + 1;
    }
    if (!spfa(1e9 + 10)) cout << "AFK";
    else cout << right;
    return 0;
}

class Solution {
public:
    int splitArray(vector<int>& nums, int k) {
        const int INF = 0x3f3f3f3f;
        int n = nums.size();
        vector<long long> sub(n + 1);
        for (int i = 0; i < n; ++i)
        {
            sub[i + 1] = nums[i] + sub[i];
        }
        vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, LLONG_MAX));
        dp[0][0] = 0;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= min(k, i); ++j)
            {
                for (int z = 0; z < i; ++z)
                {
                    dp[i][j] = min(dp[i][j], max(dp[z][j - 1], sub[i] - sub[z]));
                }
            }
        }
        return dp[n][k];
    }
};